#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10, M = N * 2;
int h1[N], e1[M], ne1[M], w1[M], idx1;
int h2[N], e2[M], ne2[M], w2[M], idx2;
int d1[N], d2[N];
vector<int>mp;
int ans[N];
int n, m;
void add1(int a, int b, int c)
{
	e1[idx1] = b, w1[idx1] = c, ne1[idx1] = h1[a], h1[a] = idx1++;
}
void add2(int a, int b, int c)
{
	e2[idx2] = b, w2[idx2] = c, ne2[idx2] = h2[a], h2[a] = idx2++;
}
void dfs1(int u, int f)
{
	for (int i = h1[u]; ~i; i = ne1[i]) {
		int j = e1[i];
		if (j != f) {
			d1[j] = d1[u] + w1[i];
			//cout << "j==" << j << "  d1[j]==" << d1[j] << endl;
			dfs1(j, u);
		}
	}
}
//void dfs2(int u, int f)
//{
//	for (int i = h2[u]; ~i; i = ne2[i]) {
//		int j = e2[i];
//		if (j != f) {
//			d2[j] = d2[u] + w2[i];
//			//cout << "j==" << j << "  d1[j]==" << d1[j] << endl;
//			dfs2(j, u);
//		}
//	}
//}
void dfs2(int u, int f)
{
	//mp.push_back(d2[u]);
	for (int i = h2[u]; ~i; i = ne2[i]) {
		int j = e2[i];
		if (j != f) {
			d2[j] = d2[u] + w2[i];
			//cout << "j==" << j << "  d2[j]==" << d2[j] << endl;
			mp.push_back(d2[j]);
			int l = -1, r = mp.size();
			while (l + 1 < r) {
				int mid = (l + r) >> 1;
				if (mp[mid] <= d1[j])l = mid;
				else r = mid;
			}
			ans[j] = l;
			dfs2(j, u);
		}
	}
	mp.pop_back();
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		scanf("%d", &n);
		idx1 = 0;
		idx2 = 0;
	/*	memset(h1, -1, sizeof(h1));
		memset(h2, -1, sizeof(h2));
		memset(d1, 0, sizeof(d1));
		memset(d2, 0, sizeof(d2));
		memset(e1, 0, sizeof(e1));
		memset(e2, 0, sizeof(e2));
		memset(ne1, 0, sizeof(ne1));
		memset(ne2, 0, sizeof(ne2));
		memset(w1, 0, sizeof(w1));
		memset(w2, 0, sizeof(w2));
		memset(ans, 0, sizeof(ans));*/
		for (int i = 2; i <= n; i++) {
			int x, v1, v2;
			scanf("%d%d%d", &x, &v1, &v2);
			add1(i, x, v1);
			add1(x, i, v1);
			add2(i, x, v2);
			add2(x, i, v2);
		}
		mp.push_back(0);
		dfs1(1, 0);
		dfs2(1, 0);
		/*for (int i = h2[2]; ~i; i = ne2[i]) {
			int j = e2[i];
			cout << "j=====" << j << " " << endl;
		}
		for (int i = 1; i <= n; i++) {
			cout << i << "==" << d1[i] << endl;
		}*/
		for (int i = 2; i <= n; i++) {
			printf("%d ", ans[i]);
		}
		printf("\n");
	}
	return 0;
}